package cn.com.sinosoft.ares.insurance.dao;

import cn.com.sinosoft.ares.insurance.model.CardUsed;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface CardusedDao {

    @Select("select * from CARDUSED where COMCODE = #{comcode} and RISKCODE=#{riskcode} and YEARS=#{years} and TYPE=#{type}")
    CardUsed selectByPrimaryKey(@Param("comcode") String comcode, @Param("riskcode") String riskcode, @Param("years") String years, @Param("type") String type);

    @Insert("<script>" +
            "insert into CARDUSED\n" +
            "    <trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n" +
            "      <if test=\"comcode != null\">\n" +
            "        COMCODE,\n" +
            "      </if>\n" +
            "      <if test=\"riskcode != null\">\n" +
            "        RISKCODE,\n" +
            "      </if>\n" +
            "      <if test=\"years != null\">\n" +
            "        YEARS,\n" +
            "      </if>\n" +
            "      <if test=\"type != null\">\n" +
            "        TYPE,\n" +
            "      </if>\n" +
            "      <if test=\"serialno != null\">\n" +
            "        SERIALNO,\n" +
            "      </if>\n" +
            "    </trim>\n" +
            "    <trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\">\n" +
            "      <if test=\"comcode != null\">\n" +
            "        #{comcode,jdbcType=VARCHAR},\n" +
            "      </if>\n" +
            "      <if test=\"riskcode != null\">\n" +
            "        #{riskcode,jdbcType=VARCHAR},\n" +
            "      </if>\n" +
            "      <if test=\"years != null\">\n" +
            "        #{years,jdbcType=VARCHAR},\n" +
            "      </if>\n" +
            "      <if test=\"type != null\">\n" +
            "        #{type,jdbcType=VARCHAR},\n" +
            "      </if>\n" +
            "      <if test=\"serialno != null\">\n" +
            "        #{serialno,jdbcType=VARCHAR},\n" +
            "      </if>\n" +
            "    </trim>" +
            "</script>")
    int insert(CardUsed cardUsed);

    @Update("update CARDUSED set serialno = #{serialno} " +
            "where comcode = #{comcode} and riskcode=#{riskcode} and years=#{years} and type=#{type}")
    int updateByPrimaryKey(CardUsed cardUsed);
}
